class MyTest10 {
    public static int count=0;
    public int x=0;
    public static void add() {
        synchronized (MyTest10.class) {
            count++;
        }
        MyTest10 myTest10 = new MyTest10();
        myTest10.x = 10;
        //System.out.println(x);
    }
    public int get() {
        return count;
    }
}
public class test10 {

    public int a=10;

        //对静态方法加锁，加在里面，需要获取类对象
    public static void main(String[] args) throws InterruptedException {
        MyTest10 myTest100 = new MyTest10();


        test10 test10 = new test10();
        test10.a = 10;
        MyTest10 myTest10 = new MyTest10();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                MyTest10.add();
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                MyTest10.add();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(myTest10.get());

    }
}
